package com.zhudi;

import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Group {
    private String groupName;
    private Set<String> members;

    public Group(String groupName) {
        this.groupName = groupName;
        this.members = new HashSet<>();
    }

    public void addMember(String username) {
        members.add(username);
    }

    public void sendMessage(String sender, String message, Map<String, PrintWriter> onlineUsers) {
        for (String member : members) {
            PrintWriter memberOut = onlineUsers.get(member);
            if (memberOut != null) {
                memberOut.println(sender + " (group " + groupName + "): " + message);
            }
        }
    }
}